<!--
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->

<polymer-element name="topeka-quiz-base" attributes="quiz" block>
<template>

  <style>
  
    /* default paddings for normal and wide layouts */
    :host {
      padding: 40px 16px;
    }
    
    :host-context(.wide) {
      padding: 40px 24px 48px;
    }
  
  </style>

</template>
<script>

  (function() {
    
    var DEFAULT_POINT = 8;

    Polymer('topeka-quiz-base', {
      
      eventDelegates: {
        tap: 'answered',
        keypress: 'keyPress'
      },
      
      isCorrect: function() {
        return this.value == this.quiz.answer;
      },
      
      getScore: function() {
        return this.isCorrect() ? (this.quiz.point || DEFAULT_POINT) : 0;
      },
      
      answered: function() {
        this.fire('quiz-answered');
      },
      
      reset: function() {
        this.value = null;
      },
      
      keyPress: function(e) {
        // enter key
        if (e.keyCode === 13) {
          this.fire('quiz-next');
          e.preventDefault();
        }
      }
      
    });
    
  })();

</script>
</polymer-element>